import '@scss/header.scss';
import '@scss/firstpage.scss';
import "@scss/motaikuang.scss";
import "bootstrap/dist/css/bootstrap.css"
import "bootstrap/dist/js/bootstrap.js"
import http from "../utils/request.js";
import { renderError, renderCollections, renderTypes, renderTiKuList, renderRankingTests, renderUsersRanking, renderUserUpdate } from "./render.js";
import "./firstShiJian.js"


(function () {
    $("#zhuye").modal("show");
    renderTypes();
    renderCollections();
    renderError();
    renderRankingTests();
    renderUsersRanking();
    renderUserUpdate();
    
})();

//修改

$("body").on("click", "#userUpdate", async function (e) {
    let user_id = localStorage.getItem("userId");
    let imagePath = $("#touXiang").attr("data");
    let userName = $("#name").val();
    let userGender = $("#gender input:checked").next().text();
    await http({ url: "/api/users/addImage", type: "post", data: {imagePath} });
    let { code } = await http({ url: "/api/users/submit", type: "post", data: { user_id, imagePath, userName, userGender } });
    if(code>0){

       $("#userUpdate").attr("data-dismiss","modal") 
    }
})

//文件上传
$("body").on("change", "#fileImg", async function (e) {
    const files = $(e.target.files);
    console.log(files);
    const fd = new FormData();
    fd.append("file", files[0]);
    $.ajax({
        url: "/api/users/uploadImage",
        type: "POST",
        data: fd,
        contentType: false,
        processData: false,
        cache: false,
        success(res) {
            console.log("文件上传成功", res);
            $("#touXiang").attr("src", `http://127.0.0.1:3000/temp/${res.data}`);
            $("#touXiang").attr("data", `${res.data}`);
        }
    })
})











